home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 050 / madtrb10.arc / STACK.DOC < prev    next >
Encoding:
Text File  |  1985-12-07  |  2.1 KB  |  49 lines

  1. The following is a Pascal assignment that I had in data structures.  It
  2. implements a stack for storing data using pointers.  It is probably of
  3. use to you if you want to learn something about stack data structures and
  4. pointers.  Before digging into the code perhaps you want to get a book on
  5. data structures and read up on what a stack is.  Happy computing!!
  6.  
  7.                                                        Chris Maeder
  8.  
  9.  
  10.                            STACK ASSIGNMENT
  11.  
  12.                            Data  Structures
  13.                                Fall 1985
  14.  
  15. Write a program that uses a stack to evaluate expressions written in Polish
  16. postfix notation.  Include separate subprograms called Push and Pop.
  17. Implement the stack using a linked list.
  18.  
  19. The parameters for Push should be a pointer variable to hold the top of the
  20. stack and a real variable to hold a number. Push creates a new node and puts
  21. it on top of the stack.
  22.  
  23. Pop needs a parameter for the top of the stack.  It returns a number.  It also
  24. disposes of the popped node.  If the stack is empty, EMPTY (set to negative
  25. maxint) is returned.  The calling routine must always check for this.
  26.  
  27. The data consists of expressions input as character strings.  Read characters
  28. in an expression until end of file is reached.
  29.  
  30. Valid operators are +, -, *, /, and ^.  A valid operand is any real or integer
  31. number with a maximum of 10 places including the decimal point if one exists.
  32. Blanks separate operators from operands.  All arithmetic should be real.  A
  33. negative number has a minus sign immediately preceding it.
  34.  
  35. Output consists of an echo print of the input expression and either the result
  36. of the evaluation of the expression or an error message.  Additional output,
  37. e.g. tracing the contents of the stack is optional but certainly useful for
  38. debugging.
  39.  
  40. Some expressions are in error so check for:
  41.  
  42.      1. An invalid character in an expression.
  43.      2. A malformed expression.
  44.  
  45. Note:
  46.  
  47.      2 5 -     is interpreted as 2-5 (not 5-2)
  48.      6 2 /     is interpreted as 6/2
  49.      4 2 ^     is interpreted as 4 squared